var t, e = (t = require("@vant/weapp/toast/toast")) && t.__esModule ? t : {
    default: t
};

var a = require("../../utils/config"), o = require("../../utils/request"), i = require("../../utils/api");

Page({
    data: {
        themeColor: getApp().globalData.themeColor,
        thumb: a.resourceRoot + "icon-report.png",
        reportList: [],
        checkedReportList: [],
        showEmpty: !1,
        active: 0,
        account: "",
        password: "",
        name: "",
        mobile: ""
    },
    onLoad: function(t) {
        var a = this;
        this.setData({
            reportList: [],
            active: t.active,
            account: t.voucherNo,
            password: t.password,
            name: t.name,
            mobile: t.checkCenterMobile
        }), 1 == t.active ? o.request(o.HttpMethod.POST, i.apiRoute.selectReportByCard, {
            account: t.voucherNo,
            password: t.password
        }).then(function(t) {
            if (wx.hideLoading(), "20000" != t.code) return a.setData({
                showEmpty: !0
            }), void (0, e.default)({
                message: t.message,
                duration: 5e3
            });
            t.data.length <= 0 ? a.setData({
                showEmpty: !0
            }) : (t.data.forEach(function(t) {
                t.date = t.date.split(" ")[0];
            }), a.setData({
                reportList: t.data
            }));
        }).catch(function(t) {
            wx.hideLoading(), console.error(t);
        }) : o.request(o.HttpMethod.POST, i.apiRoute.selectReportByNameAndMobile, {
            name: t.name,
            mobile: t.checkCenterMobile,
            verificationCode: t.smsCode
        }).then(function(t) {
            if (wx.hideLoading(), "20000" != t.code) return a.setData({
                showEmpty: !0
            }), void (0, e.default)({
                message: t.message,
                duration: 5e3
            });
            t.data.length <= 0 ? a.setData({
                showEmpty: !0
            }) : (t.data.forEach(function(t) {
                t.date = t.date.split(" ")[0];
            }), a.setData({
                reportList: t.data
            }));
        }).catch(function(t) {
            wx.hideLoading(), console.error(t);
        });
    },
    onChange: function(t) {
        this.setData({
            checkedReportList: t.detail
        });
    },
    addMyReport: function() {
        this.data.checkedReportList.length <= 0 ? (0, e.default)({
            message: "请选择需要添加的报告",
            duration: 5e3
        }) : (wx.showLoading({
            title: "正在操作中..."
        }), 1 == this.data.active ? o.request(o.HttpMethod.POST, i.apiRoute.bindWcaReportByCardAndStudyIdList, {
            account: this.data.account,
            password: this.data.password,
            studyIdList: this.data.checkedReportList
        }).then(function(t) {
            wx.hideLoading(), "20000" == t.code ? wx.reLaunch({
                url: "/pages/my-link-report/my-link-report"
            }) : (0, e.default)({
                message: t.message,
                duration: 5e3
            });
        }).catch(function(t) {
            wx.hideLoading(), console.error(t);
        }) : 0 == this.data.active && o.request(o.HttpMethod.POST, i.apiRoute.bindWcaReportByMobileAndStudyIdList, {
            name: this.data.name,
            mobile: this.data.mobile,
            studyIdList: this.data.checkedReportList
        }).then(function(t) {
            wx.hideLoading(), "20000" == t.code ? wx.reLaunch({
                url: "/pages/my-link-report/my-link-report"
            }) : (0, e.default)({
                message: t.message,
                duration: 5e3
            });
        }).catch(function(t) {
            wx.hideLoading(), console.error(t);
        }));
    }
});